<!-- Khu vực thêm module -->
<?php echo form_open('admin/setting/addModule')?>
<div class="thongbao">
<!-- Nếu có lỗi thì in ra lỗi -->
<?php if($error){?>
<div class="alert alert-error fade in">{error}<a class="close" data-dismiss="alert">&times;</a></div>
<?php }?>
</div>
<table class="websetting">
<tr>
    <td colspan="2" class="textBold" id="websettingTitle"><span class="label label-info">Thêm mới module</span></td>
</tr>
<tr>
    <td class="">Tên module</td>
    <td><input type="text" class="form" name="mod_name" id="mod_name" value=""/></td>
</tr>
<tr>
    <td class="">Controller</td>
    <td><input type="text" class="form" name="mod_control" id="mod_name" value=""/></td>
</tr>
<tr>
    <td class="">Thư mục</td>
    <td><input type="text" class="form" name="mod_view" id="mod_view" value=""/></td>
</tr>
<tr>
    <td class="">Thứ tự</td>
    <td><input type="text" class="form" name="mod_order" id="mod_order" value="0"/></td>
</tr>
<tr>
    <td class="">Tiêu đề</td>
    <td><input type="text" class="form" name="mod_action_name" id="mod_action_name" value="" size="100"/></td>
</tr>
<tr>
    <td class="">URL</td>
    <td><input type="text" class="form" name="mod_action_link" id="mod_action_link" value="" size="100"/></td>
</tr>
<tr>
    <td>&nbsp;</td>
    <td><input type="submit" value="Thêm mới module" class="form"/></td>
</tr>
</table>
<hr />
<?php echo form_close()?>

<!-- Khu vực danh sách module + sửa xóa -->

<div id="listmodule">
{list}
    <div class="detailmodule">
        <div class="thongbao"></div>
        <table class="websetting">
        <tr>
            <td colspan="2" class="textBold" id="websettingTitle">
            <i class="icon-folder-open"></i> {mod_name}<span class="saveBtn label label-important">Lưu</span><span class="deleteBtn label">Xóa</span>
            </td>
        </tr>
        <tr>
            <td>Module id</td>
            <td id="mod_id">{mod_id}</td>
        </tr>
        <tr>
            <td>Tên module</td>
            <td><?php echo form_input('mod_name','{mod_name}','id="mod_name"') ?></td>
        </tr>
        <tr>
            <td>Controller</td>
            <td><?php echo form_input('mod_control','{mod_control}','id="mod_control"') ?></td>
        </tr>
        <tr>
            <td>Thư mục</td>
            <td><?php echo form_input('mod_view','{mod_view}','id="mod_view"') ?></td>
        </tr>
        <tr>
            <td>Thứ tự</td>
            <td><?php echo form_input('mod_order','{mod_order}','id="mod_order"') ?></td>
        </tr>
        <tr>
            <td>Tiêu đề</td>
            <td><?php echo form_input('mod_action_name','{mod_action_name}','id="mod_action_name"') ?></td>
        </tr>
        <tr>
            <td>URL</td>
            <td><?php echo form_input('mod_action_link','{mod_action_link}','id="mod_action_link"') ?></td>
        </tr>
        </table>
    </div><hr />
{/list}
</div>
<script>
//Sửa module
$('.saveBtn').click(function(){
    $module = $(this).closest('.detailmodule');
    $thongbao = $module.find('.thongbao');
    data = {
        'ajax':1,
        'mod_id':$module.find('#mod_id').text(),
        'mod_name':$module.find('#mod_name').val(),
        'mod_control':$module.find('#mod_control').val(),
        'mod_view':$module.find('#mod_view').val(),
        'mod_order':$module.find('#mod_order').val(),
        'mod_action_name':$module.find('#mod_action_name').val(),
        'mod_action_link':$module.find('#mod_action_link').val()
    }
    $.ajax({
        type:'POST',
        url:'editModule',
        data:data,
        dataType:'html',
        success:function(alert){
            if($thongbao.children().size() == 0){
                $thongbao.append('<div class="alert alert-success fade in">'+alert+'<a class="close" data-dismiss="alert">&times;</a></div>');    
            }
        }
    });
});
//Xóa module
$('.deleteBtn').click(function(){
    $module = $(this).closest('.detailmodule');
    $thongbao = $module.find('.thongbao');
    data = {
        'ajax':1,
        'mod_id':$module.find('#mod_id').text()
    };
    $.ajax({
        type:'POST',
        url:'deleteModule',
        data:data,
        dataType:'html',
        success:function(alert){
            if($thongbao.children().size() == 0){
                $thongbao.append('<div class="alert alert-success fade in">'+alert+'<a class="close" data-dismiss="alert">&times;</a></div>');    
            }
        }
    });
});
</script>